package com.hjl.controller;

import com.hjl.pojo.Headline;
import com.hjl.service.HeadlineService;
import com.hjl.utils.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.Map;

/**
 * @author ServivE
 * @version 0.1
 * @className HeadLineController
 * @description
 * @date 2024/8/23 19:35
 * @since jdk17
 */
@RestController
@RequestMapping("headline")
@CrossOrigin
public class HeadLineController {
    @Autowired
    private HeadlineService headlineService;

    //发布内容
    @PostMapping("publish")//根据请求头里的token获取userId，查询发布者
    public Result publish(@RequestBody Headline headline, @RequestHeader String token) {
        Result result = headlineService.publish(headline, token);
        return result;
    }

    //修改头条回显
    @PostMapping("findHeadlineByHid")
    public Result findHeadlineByHid(Integer hid) {
        //mybatisplus提供给service层也有curd方法
        Headline headline = headlineService.getById(hid);
        Map data = new HashMap();
        data.put("headline", headline);
        return Result.ok(null);
    }

    //修改数据
    @PostMapping("update")
    public Result update(@RequestBody Headline headline) {
        Result result = headlineService.updateData(headline);
        return result;
    }


    //删除(逻辑删除）
    @PostMapping("removeByHid")
    public Result removeByHid(Integer hid) {
        headlineService.removeById(hid);
        return Result.ok(null);
    }
}
